package com.bonnemai.eqd.server;

import com.bonnemai.eqd.client.PricingService;
import com.bonnemai.eqd.shared.Results;
import com.bonnemai.eqd.shared.Vanilla;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class PricingServiceImpl extends RemoteServiceServlet implements
		PricingService {

	public Results priceServer(Vanilla vanilla) throws IllegalArgumentException {
		EquityOption equityOption=new EquityOption(vanilla);
		Results results = new Results();
		results.setNpv(equityOption.getJQuantLibVanillaOption().NPV());
		results.setDelta(equityOption.getJQuantLibVanillaOption().delta());
		results.setGamma(equityOption.getJQuantLibVanillaOption().gamma());
		return results;
	}

	/**
	 * Escape an html string. Escaping data received from the client helps to
	 * prevent cross-site script vulnerabilities.
	 * 
	 * @param html the html string to escape
	 * @return the escaped string
	 */
	@SuppressWarnings("unused")
	private String escapeHtml(String html) {
		if (html == null) {
			return null;
		}
		return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;")
				.replaceAll(">", "&gt;");
	}
}
